Telegram Group & Telegram Channel
🐼 Задача на знание Pandas

Условие: У вас есть датафрейм df, содержащий два столбца: A и B. Столбец A содержит даты, а столбец B — числовые значения. Как бы вы рассчитали скользящее среднее по столбцу B с окном в 3 дня, предполагая, что значения в столбце A идут подряд и без пропусков?

Решение:
import pandas as pd

data = {
'A': ['2023-01-01', '2023-01-02', '2023-01-03', '2023-01-04', '2023-01-05',
'2023-01-06', '2023-01-07', '2023-01-08', '2023-01-09'],
'B': [18, 71, 13, 57, 7, 8, 69, 83, 27]
}

df = pd.DataFrame(data)

# Убедимся, что столбец A распознан как дата
df['A'] = pd.to_datetime(df['A'])

# Установим столбец дат как индекс датафрейма
df = df.set_index('A')

# Рассчитаем скользящее среднее по столбцу B с окном в 3 дня
df['Moving_Average'] = df['B'].rolling(window=3).mean()

print(df)


#python
#pandas
#программирование
Please open Telegram to view this post
VIEW IN TELEGRAM



tg-me.com/ds_interview_lib/247
Create:
Last Update:

🐼 Задача на знание Pandas

Условие: У вас есть датафрейм df, содержащий два столбца: A и B. Столбец A содержит даты, а столбец B — числовые значения. Как бы вы рассчитали скользящее среднее по столбцу B с окном в 3 дня, предполагая, что значения в столбце A идут подряд и без пропусков?

Решение:

import pandas as pd

data = {
'A': ['2023-01-01', '2023-01-02', '2023-01-03', '2023-01-04', '2023-01-05',
'2023-01-06', '2023-01-07', '2023-01-08', '2023-01-09'],
'B': [18, 71, 13, 57, 7, 8, 69, 83, 27]
}

df = pd.DataFrame(data)

# Убедимся, что столбец A распознан как дата
df['A'] = pd.to_datetime(df['A'])

# Установим столбец дат как индекс датафрейма
df = df.set_index('A')

# Рассчитаем скользящее среднее по столбцу B с окном в 3 дня
df['Moving_Average'] = df['B'].rolling(window=3).mean()

print(df)


#python
#pandas
#программирование

BY Библиотека собеса по Data Science | вопросы с собеседований


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/ds_interview_lib/247

View MORE
Open in Telegram


Библиотека собеса по Data Science | вопросы с собеседований Telegram | DID YOU KNOW?

Date: |

What is Telegram?

Telegram’s stand out feature is its encryption scheme that keeps messages and media secure in transit. The scheme is known as MTProto and is based on 256-bit AES encryption, RSA encryption, and Diffie-Hellman key exchange. The result of this complicated and technical-sounding jargon? A messaging service that claims to keep your data safe.Why do we say claims? When dealing with security, you always want to leave room for scrutiny, and a few cryptography experts have criticized the system. Overall, any level of encryption is better than none, but a level of discretion should always be observed with any online connected system, even Telegram.

The S&P 500 slumped 1.8% on Monday and Tuesday, thanks to China Evergrande, the Chinese property company that looks like it is ready to default on its more-than $300 billion in debt. Cries of the next Lehman Brothers—or maybe the next Silverado?—echoed through the canyons of Wall Street as investors prepared for the worst.

Библиотека собеса по Data Science | вопросы с собеседований from us


Telegram Библиотека собеса по Data Science | вопросы с собеседований
FROM USA